define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'pt/patent_and_softbook/index' + location.search,
                    add_url: 'pt/patent_and_softbook/add',
                    edit_url: 'pt/patent_and_softbook/edit',
                    del_url: 'pt/patent_and_softbook/del',
                    multi_url: 'pt/patent_and_softbook/multi',
                    import_url: 'pt/patent_and_softbook/import',
                    table: 'pt_patent_and_softbook',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                sortOrder: 'asc',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'types', title: __('Types') ,},
                        {field: 'types', title: __('Types'), searchList:{'1':'软著','2':'发明专利','3':'实用新型专利','4':'外观设计专利'}, formatter:function(v,r,index){ 
                            let type_name = '';
                            switch (v) {
                                case 1:
                                    type_name = '软著';
                                    break;
                                case 2:
                                    type_name = '发明专利';
                                    break;
                                case 3:
                                    type_name = '实用新型专利';
                                    break;
                                case 4:
                                    type_name = '外观设计专利';
                                    break;
                                default:
                                    type_name = '未知';
                                    break;
                            }
                            return `<span class="label label-primary">${type_name}</span>`;
                        }},
                        {field: 'agency', title: __('Agency'), operate: 'LIKE'},
                        {field: 'write_fee', title: __('Write_fee'), operate:false},
                        {field: 'agency_fee', title: __('Agency_fee'), operate:false},
                        {field: 'official_fee', title: __('Official_fee'), operate:false},
                        {field: 'administrative_fee', title: __('Administrative_fee'), operate:false},
                        {field: 'remarks', title: __('Remarks'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
